Backup Scripts in a UNIX Environment

    Various text files are provided for UNIX backups. The main backup script 
reads the schedule to determine the kind of backup to be taken. Then it calls 
other procedures to actually take a cold backup, a hot backup, or an export of
the database. The scripts should give you an idea on the kind of logic to use
while automating backup procedures. 

   We have tried not to hardcode any values in the scripts. We have tried 
to obtain information from the database whenever possible,  or used environment
variables which can be set to suit your needs. You should customize the scripts
for your business needs and test them before using them in a production 
environment.

   The main procedure is called dbbackup.  This procedure always does the 
following:

o  Sets up the environment variables specific to the database by running the 
   shell script $TOOLS/db_admin/common/crontab.env.

o  Reads the backup schedule from $TOOLs/db_admin/common/dbbackup_sched.dat 
   file to determine whether to take a hot backup, cold backup or an export 
   of the database

o  Calls the procedure dbbackup_begin to do a hot or cold backup

o  Calls the procedure dbexport_begin to do a full database export


  The procedure dbbackup_begin does the following:

o  Builds a dynamic listing of database files, control files and location of
   archive log files for use by hot and cold backups

o  Performs hot backup by executing the following steps:

	-  Each tablespace is put into hot backup mode
	-  Data files are copied
	-  Ends hot backup mode for that tablespace
	-  A log switch is forced before the archive logs are copied
	-  Only a single control file backup is made

o  Performs cold backups by executing the following steps:

	- Send warning messages to users notifying them of the impending 
	  database shutdown
	- The database is shutdown 
	- Copies all database files, control files and archive logs
	- Optionally, starts the database in restricted mode and performs DBA 
	  tasks, and shuts down again
	- Restarts the database, and sends message to users

  The procedure dbexport_begin does the following:

	- Takes a backup of the previous export file by copying it from the 
	  current location to a backup location
	- Deletes the export file in the current location
	- Performs the export using the parameter file 
	  $TOOLS/db_admin/db_<dbname>/export.par

Related fies:

$TOOLS/backup/dbbackup				main routine
$TOOLS/backup/dbbackup_begin			called by dbbackup
$TOOLS/ /backup/dbexport_begin 			called by dbbackup
$TOOLS/db_admin/common/dbbackup_sched.dat	backup schedule file
$TOOLS/db_admin/common/crontab.env 		sets environment variables
$TOOLS/db_admin/db_dbname/log 			directory containing logs 
						written by the backup and 
						export scripts
$TOOLS/db_admin/db_dbname/export.par 		export parameter file



The directory structure that is required by these scripts is: 

$TOOLS				- top level directory,  needs to be set in the 
				  environment before the scripts are executed
$TOOLS/backup			- location of backup scripts
$TOOLS/db_admin/common		- Administrative files common to all databases
$TOOLS/db_admin/db_dbname	- Administrative  files specific to each 
				  database
$TOOLS/db_admin/db_dbname/log	- Log files


 While creating scripts in UNIX always remember the following general rules:

  Never use cd in a script; always use absolute paths of files.
  Never refer to files with wildcards.
  Always verify file copies using the cksum command.
  Always check the return status of shell commands to verify their 
  success or failure.
  Always check whether a file or directory exists with the -f option.



	We assume that all the backup files are kept in the same directory.  
You may want to modify this such that the directory structure of the original 
database files is maintained. You also need to determine whether you want to 
copy all data files to one disk, to more than one disk, or to tape, and 
customize the scripts accordingly.
